<template>
	<view class="cooperate">
		<u-form labelPosition="top" :model="formData" :rules="rules" labelWidth="300rpx" ref="form">
			<u-form-item label="留下您的姓名" prop="name" required borderBottom>
				<u-input v-model="formData.name" placeholder="请输入" border="none" />
			</u-form-item>
			<u-form-item label="联系您的联系方式" prop="phone" required>
				<u-input v-model="formData.phone" placeholder="请输入" border="none" type="number" />
			</u-form-item>
			<u-form-item label="咨询" prop="content" required>
				<u-input v-model="formData.content" placeholder="请输入" border="none" />
			</u-form-item>
		</u-form>

		<u-button text="提交" shape="circle" @click="submit"
			color="linear-gradient(0deg, #0E9698 0%, #0E9698 100%)"></u-button>
	</view>
</template>

<script>
	const index = require("@/api/index/index.js");
	export default {
		data() {
			return {
				formData: {
					name: '',
					phone:'',
					content:''
				},
				rules: {
					name: {
						required: true,
						message: '请输入您的姓名',
						trigger: ['change'],
					},
					phone: {
						required: true,
						message: '请输入您的联系方式',
						trigger: ['change'],
					},
					content: {
						required: true,
						message: '请输入咨询',
						trigger: ['change'],
					},
				},
			}
		},
		onReady() {
			this.$refs.form.setRules(this.rules);
		},
		methods: {
			submit() {
				// 轮播信息
				index.cooperationadd({
					name: this.formData.name,
					phone: this.formData.phone,
					content: this.formData.content,
				}).then(res => {
					if (res.code == 1) {
						uni.switchTab({
							url: '/pages/personal/personal', //跳去登录页
						})
					}
					if (res.code == 0) {
						uni.showToast({
							title: res.msg,
							duration: 2000,
							icon: 'none'
						});
					}
					if (res.code == '-1') {
						uni.clearStorage();
						uni.clearStorageSync();
						uni.removeStorageSync('token')
						uni.clearStorage({
							success: function(_) {
								uni.showModal({
									title: '退出登录成功',
									showCancel: false,
								})
							},
							fail: function(_) {
								uni.showModal({
									title: '退出登录失败',
									showCancel: false,
								})
							},
						})
						uni.switchTab({
							url: '/pages/personal/personal', //跳去登录页
						})
					}
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.cooperate {
		min-height: 100vh;
		background-color: #f3f3f3;
		padding: 30rpx;

		/deep/.u-form {
			background-color: #fff;
			border-radius: 10rpx;
			margin-bottom: 20rpx;
			padding: 20rpx 0;

			.u-form-item {
				padding: 0 30rpx;
			}
		}
	}
</style>